/*
 * This file Copyright (c) 2015. Walle.
 * (http://www.wallellen.com). All rights reserved.
 *
 *
 * This file is dual-licensed under both the
 * Walle Agreement (WA) and the GNU General Public License.
 * You may elect to use one or the other of these licenses.
 *
 * This file is distributed in the hope that it will be
 * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
 * Redistribution, except as permitted by whichever of the GPL
 * or WA you select, is prohibited.
 *
 * 1. For the GPL license (GPL), you can redistribute and/or
 * modify this file under the terms of the GNU General
 * Public License, Version 3, as published by the Free Software
 * Foundation.  You should have received a copy of the GNU
 * General Public License, Version 3 along with this program;
 * if not, write to the Free Software Foundation, Inc., 51
 * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * 2. For the Walle Agreement (WA), this file
 * and the accompanying materials are made available under the
 * terms of the WA which accompanies this distribution, and
 * is available at http://www.wallellen.com/agreement.html
 *
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
 */

/**
 *
 */
package com.wallellen.wechat.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author <a href="mailto:wallellen@hotmail.com">WALLE</a>
 * @date 2014年12月8日
 */
public class Config {

    private static Logger logger = LoggerFactory.getLogger(Config.class);

    private static final String configFile = "/wechat4j.properties";

    private String url;
    private String token;
    private String encodingAESKey;
    private String appid;
    private String appSecret;
    private String accessTokenServer;
    private String jsApiTicketServer;
    private static Config config = new Config();

    private Config() {
        Properties p = new Properties();
        InputStream inStream = this.getClass().getResourceAsStream(configFile);
        if (inStream == null) {
            logger.error("根目录下找不到wechat4j.properties文件");
            return;
        }
        try {
            p.load(inStream);
            this.url = p.getProperty("wechat.url").trim();
            this.encodingAESKey = p.getProperty("wechat.encodingaeskey").trim();
            this.token = p.getProperty("wechat.token").trim();
            this.appid = p.getProperty("wechat.appid").trim();
            this.appSecret = p.getProperty("wechat.appsecret").trim();
            this.accessTokenServer = p.getProperty("wechat.accessToken.server.class").trim();
            this.jsApiTicketServer = p.getProperty("wechat.ticket.jsapi.server.class").trim();
            inStream.close();
        } catch (IOException e) {
            logger.error("load wechat4j.properties error,class根目录下找不到wechat4j.properties文件");
            e.printStackTrace();
        }
        logger.info("load wechat4j.properties success");
    }

    public static Config instance() {
        return config;
    }

    public String getToken() {
        return token;
    }

    public String getAppid() {
        return appid;
    }

    public String getAppSecret() {
        return appSecret;
    }

    public String getUrl() {
        return url;
    }

    public String getEncodingAESKey() {
        return encodingAESKey;
    }

    public String getAccessTokenServer() {
        return accessTokenServer;
    }

    public String getJsApiTicketServer() {
        return jsApiTicketServer;
    }


}
